package cn.htsyb.synergy.orm.jpa.model.param;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
 *
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @date 2022/5/11
 * @since 1.0
 */
@Data
@Schema(description = "分页的请求参数类")
public class PageParam {

    @Schema(name = "page", description = "当前页码,默认1")
    protected Integer page = 1;
    @Schema(name = "size", description = "页记录数,默认15")
    protected Integer size = 15;
    @Schema(name = "order", description = "排序条件,示例：field,field2 desc,field3 asc")
    protected String order;

    public Integer getPage() {
        //默认情况下，Pageable中的page是从0开始的;为了业务理解,前端传参从1开始,因此，这里做个减1处理
        return (page > 0 ? (page - 1) : 0);
    }

    public Integer getStart() {
        return getPage() * getSize();
    }

}
